package com.oracle.coherence.patterns.security.extend;

import com.oracle.coherence.patterns.security.accesscontrol.Action;

/**
 * This enum represents different actions that can be performed on an invocation service.
 *
 * @author Jonathan Knight
 */
public enum InvokeAction implements Action {
    NONE(0x0000),
    ALL(-1),
    EXECUTE(0x001),
    QUERY(0x0010);

    private int flagValue;
    private String name;

    InvokeAction(int flagValue) {
        this(flagValue, null);
    }

    InvokeAction(int flagValue, String name) {
        this.flagValue = flagValue;
        this.name = name;
    }

    @Override
    public int getFlagValue() {
        return flagValue;
    }

    @Override
    public String getActionName() {
        return (name != null) ? name : this.toString().toLowerCase();
    }

    @Override
    public Action fromName(String name) {
        for (InvokeAction action : InvokeAction.values()) {
            if (action.getActionName().equalsIgnoreCase(name)) {
                return action;
            }
        }

        throw new IllegalArgumentException("name [" + name + "] does not match any InvokeAction name");
    }

    @Override
    public Action[] actionList() {
        return InvokeAction.values();
    }


}
